﻿using dsf.scenery.order.finance.MongoHelper;
using QuestionInvestig.Model;
using QuestionInvestig.MongoHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuestionInvestig.Business
{
    public class QuestionInsertService
    {
        public static Response quesInsert(Requestentity request)
        {
            bool success = false;
            try
            {
                if (string.IsNullOrEmpty(request.title) || string.IsNullOrEmpty(request.content))
                {
                    return new Response { ifsuccess = false, errmsg = "传入参数有误或为空！" };
                }
                Mongo mservice = new Mongo();
                string keyid = Guid.NewGuid().ToString();
                //string keyid = Mongo.GetDocument();
                //Configentity c = new Configentity();
                //c.id = keyid;
               // c.content = request.title;
                QuestionAnswerModel model = new QuestionAnswerModel();
                model.QuestionSerialId = keyid;
                model.CreateName = "admin";
                model.CreateTime = DateTime.Now;
                model.IsValid = 1;
                model.QuesTitle = request.title;
                model.Type = 1;//类型
                Listentity l = new Listentity();
                l.id = keyid;
                l.content= request.content;
                mservice.Insert(model, MongoDbManager.QuestionConfiguration);
                mservice.Insert(l, MongoDbManager.QuestionList);
                success = true;
            }
            catch (Exception ex)
            {
                return new Response { ifsuccess = success, errmsg = ex.Message };
            }
            return new Response { ifsuccess = success, errmsg = "" };
        }
    }


    public class Requestentity
    {

        /// <summary>
        /// 状态
        /// </summary>
        public string title { set; get; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string content { set; get; }


    }
    public class Response
    {

        /// <summary>
        /// 状态
        /// </summary>
        public bool ifsuccess{ set; get; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string errmsg { set; get; }


    }


    public class Configentity
    {

        /// <summary>
        /// 状态
        /// </summary>
        public string id { set; get; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string content { set; get; }


    }
    public class Listentity
    {

        /// <summary>
        /// 状态
        /// </summary>
        public string id { set; get; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string content { set; get; }


    }
}
